/**
 * Created on 13 avr. 08 by Sebastian Audet
 */
package gui2Dengine;

import grid.Grid;
import grid.GridOutOfBounds;
import grid.Location;

import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author Sebastian Audet
 * 
 */
public class SquareDisplayMap extends DisplayMap {

    SquareDisplayMap(Grid grid, double length, double width) {
	super(grid, length, width);
	shapes = new ArrayList<Shape>();
	shapemap = new HashMap<Location,Shape>();
    }

    @Override
    public void generateShapeData(int xoffset, int yoffset, int xunits,
	    int yunits) {
	// Generate SquareGrid shape data
	Point p = new Point(0, 0);
	for (int i = 0; i < yunits; i++) {
	    for (int j = 0; j < xunits; j++) {
		Shape shape = new Rectangle2D.Double(p.x + (j * length), p.y + (i * length),length,length);
		Location loc = null;
		try {
		    loc = grid.getNode(
			    new Location(j + yoffset, i + xoffset))
			    .getLocation(); 
		    shapemap.put(loc, shape);
		    shapes.add(shape);
		} catch (GridOutOfBounds e) {
		    e.printStackTrace();
		} catch (NullPointerException e)
		{
		    System.out.println(loc);
		}
	    }
	} // End SquareGrid Code
    }

}
